<?php
/**
 * Created by PhpStorm.
 * User: VJLau
 * Date: 2018/2/5
 * Time: 下午12:29
 */

$id = intval($_GPC['id']);
$type = trim($_GPC['type']);
$uniacid = $_W['uniacid'];
if (empty($id)) message('参数错误', $this->createMobileUrl('list'), 'error');
if (empty($type)) message('参数错误', $this->createMobileUrl('list'), 'error');
// 商品详细
switch ($type) {
    case "single":
        $goods = pdo_fetch("SELECT sg.*,currency.exchange_rate FROM " . tablename('bontrip_single')
            . " AS sg LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = sg.currency_id WHERE sg.uniacid = '{$uniacid}' AND sg.id = '{$id}' and sg.deleted_at is null");
        break;
    case "oneday":
        $goods = pdo_fetch("SELECT od.*,currency.exchange_rate FROM " . tablename('bontrip_oneday')
            . " AS od LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = od.currency_id WHERE od.uniacid = '{$uniacid}' AND od.id = '{$id}' and od.deleted_at is null");
        break;
    case "quality":
        $goods = pdo_fetch("SELECT ql.*,currency.exchange_rate FROM " . tablename('bontrip_quality')
            . " AS ql LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = ql.currency_id WHERE ql.uniacid = '{$uniacid}' AND ql.id = '{$id}' and ql.deleted_at is null");
        break;
    default:
        message('参数错误', $this->createMobileUrl('list'), 'error');
        break;
}
if (empty($goods)) {
    message('商品不存在或已下架', $this->createMobileUrl('list'), 'error');
}

if (!empty($goods['thumbs'])) {
    $goods['thumbs'] = unserialize($goods['thumbs']);
}

//获取sku列表
$goods['sku'] = unserialize($goods['sku']);
if (!empty($goods['sku'])) {
    $sku_list = $goods['sku'];
}

$goods['product_desc'] = unserialize($goods['product_desc']);
$goods['product_desc']['desc'] = explode('占位符', str_replace(PHP_EOL, '占位符', $goods['product_desc']['desc']));
if (!empty($goods['product_desc']['trip'])) {
    //替换换行符
    foreach ($goods['product_desc']['trip'] as $key => $val) {
        $goods['product_desc']['trip'][$key]['trip_desc'] = explode('占位符', str_replace(PHP_EOL, '占位符', $goods['product_desc']['trip'][$key]['trip_desc']));
    }
}

$goods['price_desc'] = unserialize($goods['price_desc']);
if (!empty($goods['price_desc']['price'])) {
    //替换换行符
    foreach ($goods['price_desc']['price'] as $key => $val) {
        $goods['price_desc']['price'][$key]['price_desc'] = explode('占位符', str_replace(PHP_EOL, '占位符', $goods['price_desc']['price'][$key]['price_desc']));
    }
}
$goods['use_desc'] = unserialize($goods['use_desc']);
if (!empty($goods['use_desc']['use'])) {
    //替换换行符
    foreach ($goods['use_desc']['use'] as $key => $val) {
        $goods['use_desc']['use'][$key]['use_desc'] = explode('占位符', str_replace(PHP_EOL, '占位符', $goods['use_desc']['use'][$key]['use_desc']));
    }
}

$goods['buy_desc'] = unserialize($goods['buy_desc']);
if (!empty($goods['buy_desc']['buy'])) {
    //替换换行符
    foreach ($goods['buy_desc']['buy'] as $key => $val) {
        $goods['buy_desc']['buy'][$key]['buy_desc'] = explode('占位符', str_replace(PHP_EOL, '占位符', $goods['buy_desc']['buy'][$key]['buy_desc']));
    }
}
//记录url
$_SESSION['jump_url'] = url('entry', array('m' => 'vj_bontrip', 'do' => 'goods', 'id' => $id, 'type' => $type), true);
$is_login = empty($_SESSION['vj_member']) ? '0' : '1';
$title = '填写订单';
include $this->template('goods');
